package com.wltt.product.frfront.executors;

import com.wltt.product.frfront.holder.RobotHolder;
import com.wltt.product.frfront.model.vo.CommonWeldREQ;
import com.wltt.product.frfront.model.vo.WeldREQ;
import fairino.Robot;

public abstract class WeldTool {

    public static void stopWeld(Robot robot, WeldREQ weldREQ, boolean weaveEnd, boolean ARCEnd) {
        try {
            robot.StopMotion();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            if (weaveEnd && weldREQ.getSwingEnabled()) {
                robot.WeaveEnd(RobotHolder.getRobot().getRobotPO().getWeaveConfigNum());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            if (ARCEnd && weldREQ.getWeldEnabled()) {
                robot.ARCEnd(0, RobotHolder.getRobot().getRobotPO().getArcConfigNum(), 10000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void stopWeld(Robot robot, CommonWeldREQ weldREQ, boolean weaveEnd, boolean ARCEnd) {
        try {
            robot.StopMotion();
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            if (ARCEnd && weldREQ.getWeldEnabled()) {
                robot.ARCEnd(0, RobotHolder.getRobot().getRobotPO().getArcConfigNum(), 10000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {
            if (weaveEnd && weldREQ.getSwingEnabled()) {
                robot.WeaveEnd(RobotHolder.getRobot().getRobotPO().getWeaveConfigNum());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 计算速度基于最大速度1m/s或6000cm/m
     *
     * @param speed 需要的最大速度cm/m
     * @return
     */
    public static SpeedBO calculateSpeed(int speed) {
        if (speed <= 6) {
            return new SpeedBO(1, speed / 60);
        }
        if (speed <= 300) {
            return new SpeedBO(5, speed / 300);
        }
        if (speed <= 600) {
            return new SpeedBO(10, speed / 600);
        }
        if (speed <= 1200) {
            return new SpeedBO(20, speed / 1200);
        }
        if (speed <= 2400) {
            return new SpeedBO(40, speed / 2400);
        }
        if (speed <= 4800) {
            return new SpeedBO(80, speed / 4800);
        }
        if (speed <= 6000) {
            return new SpeedBO(100, speed / 6000);
        }
        return new SpeedBO(100, 100);
    }
}
